import {AfterContentChecked, AfterContentInit, AfterViewInit, Component, DoCheck, OnChanges, OnInit} from '@angular/core';
import {NavController, ViewDidEnter, ViewWillEnter} from '@ionic/angular';
import {ActivatedRoute, Router} from '@angular/router';
import {EventService} from '../wzqService/event.service';

@Component({
  selector: 'app-tab1',
  templateUrl: 'tab1.page.html',
  styleUrls: ['tab1.page.scss']
})
export class Tab1Page implements OnInit, AfterContentInit, ViewWillEnter, ViewDidEnter, AfterViewInit, AfterContentChecked, DoCheck, OnChanges {

  public scanText; // 扫码识别到的数据

  constructor(
    private nav: NavController,
    private myRouter: Router,
    public activeRoute: ActivatedRoute,
    public eventService: EventService
  ) {
    console.log('tab1-constructor');

    // 需要接收ScanPage传递来的参数,并显示在视图中
    // 当前页面监听扫码事件广播
    this.eventService.eventEmit.on('scanPageCloseEvent', (result) => {
      console.log('执行 result=', result);
      this.scanText = result;
      alert(this.scanText);
    });
  }

  ngOnInit() {
    console.log('tab1-ngOnInit');
  }

  ngAfterContentInit() {
    console.log('tab1-ngAfterContentInit');
  }

  ngOnChanges() {
    console.log('tab1-ngOnChanges');
  }

  ngDoCheck() {
    // 有变动就执行
  }

  ngAfterViewInit() {
    console.log('tab1-ngAfterViewInit');
  }

  ngAfterContentChecked() {
    // 有变动就执行
  }

  ionViewDidLoad() {
    console.log('1.0 ionViewDidLoad 当页面加载的时候触发，仅在页面创建的时候触发一次，如果被缓存了，那么下次再打开这个页面则不会触发');
  }

  ionViewWillEnter() {
    console.log('2.0 ionViewWillEnter 顾名思义，当将要进入页面时触发');
  }

  ionViewDidEnter() {
    console.log('3.0 ionViewDidEnter 当进入页面时触发');
  }

  ionViewWillLeave() {
    console.log('4.0 ionViewWillLeave 当将要从页面离开时触发');
  }

  ionViewDidLeave() {
    console.log('5.0 ionViewDidLeave 离开页面时触发');
  }


  // 跳转到 scan 并发送参数
  async sendArg() {
    await this.nav.navigateForward(['/scan']);
  }

}
